package com.ruoyi.shop.domain;

import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.shop.util.pay.PayStatus;
import com.ruoyi.shop.util.pay.PaymentRecordConstants;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 支付记录对象 shop_payment_record
 * 
 * @author Alan Zhang
 * @date 2021-09-14
 */
public class ShopPaymentRecord extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** 支付记录id */
    private Long id;

    /** 商品名称 */
    @Excel(name = "商品名称")
    private String productTitle;

    /** 产品描述，产品摘要 */
    @Excel(name = "产品描述")
    private String productSummary;

    /** 相关产品ID */
    @Excel(name = "相关产品ID")
    private String productRelativeId;

    /** 相关产品类型 */
    @Excel(name = "相关产品类型")
    private String productRelativeType;

    /** 相关产品内容 */
    @Excel(name = "相关产品内容")
    private String productRelativeTypeText;

    /** 支付流水号 */
    @Excel(name = "支付流水号")
    private String trxNo;

    /** 交易业务类型  1消费、2充值等 */
    @Excel(name = "交易业务类型")
    private String trxType;

    /** 签名随机字符串，一般是用来防止重放攻击 */
    private String trxNonceStr;

    /** 付款人编号 */
    @Excel(name = "付款人编号")
    private Long payerUserId;

    /** 付款人名称 */
    @Excel(name = "付款人名称")
    private String payerName;

    /** 付款方手续费 */
    @Excel(name = "付款方手续费")
    private BigDecimal payerFee;

    /** 下单ip(客户端ip,从网关中获取) */
    private String orderIp;

    /** 订单来源 */
    @Excel(name = "订单来源")
    private String orderFrom;

    /** 支付状态：1生成订单未支付（预支付）、 2支付失败、 9自动在线支付成功、 10支付宝转账支付成功、 11微信转账支付成功、 12线下支付支付成功（一般是银行转账等）、 13其他支付方式支付成功 */
    @Excel(name = "支付状态")
    private Integer payStatus;

    /** 支付类型编号 */
    @Excel(name = "支付类型编号")
    private String payType;

    /** 支付银行类型 */
    @Excel(name = "支付银行类型")
    private String payBankType;

    /** 订单金额 */
    @Excel(name = "订单金额")
    private BigDecimal payAmount;

    /** 成功支付金额 */
    @Excel(name = "成功支付金额")
    private BigDecimal paySuccessAmount;

    /** 支付成功时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "支付成功时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date paySuccessTime;

    /** 支付证明，手动入账时需要截图 */
    @Excel(name = "支付证明")
    private String paySuccessProof;

    /** 支付备注 */
    @Excel(name = "支付备注")
    private String paySuccessRemarks;

    /** 完成时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "完成时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date payCompleteTime;

    /** 退款流水号 */
    @Excel(name = "退款流水号")
    private String refundNo;

    /** 退款金额 */
    @Excel(name = "退款金额")
    private Long refundAmount;

    /** 退款描述 */
    @Excel(name = "退款描述")
    private String refundDesc;

    /** 退款时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "退款时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date refundTime;

    /** 第三方支付平台 */
    @Excel(name = "第三方支付平台")
    private String thirdpartyType;

    /** 微信appid 或者 支付宝的appid，thirdparty 指的是支付的第三方比如微信、支付宝、PayPal等 */
    @Excel(name = "第三方appid")
    private String thirdpartyAppid;

    /** 商户号 */
    @Excel(name = "商户号")
    private String thirdpartyMchId;

    /** 交易类型 */
    @Excel(name = "交易类型")
    private String thirdpartyTradeType;

    /** 第三方交易id */
    @Excel(name = "第三方交易id")
    private String thirdpartyTransactionId;

    /** 第三方用户openid */
    @Excel(name = "第三方用户openid")
    private String thirdpartyUserOpenid;
    /** 第三方prepayId */
    @Excel(name = "第三方prepayId")
    private String thirdpartyPrepayid;

    /** payment状态：1预支付、 2支付失败、 9支付成功、 11预退款、 12退款中、 13退款失败、 19退款成功 */
    @Excel(name = "状态")
    private Integer status;

    public void setId(Long id) 
    {
        this.id = id;
    }

    public Long getId() 
    {
        return id;
    }
    public void setProductTitle(String productTitle) 
    {
        this.productTitle = productTitle;
    }

    public String getProductTitle() 
    {
        return productTitle;
    }
    public void setProductSummary(String productSummary) 
    {
        this.productSummary = productSummary;
    }

    public String getProductSummary() 
    {
        return productSummary;
    }
    public void setProductRelativeId(String productRelativeId) 
    {
        this.productRelativeId = productRelativeId;
    }

    public String getProductRelativeId() 
    {
        return productRelativeId;
    }
    public void setProductRelativeType(String productRelativeType) 
    {
        this.productRelativeType = productRelativeType;
    }

    public String getProductRelativeType() 
    {
        return productRelativeType;
    }
    public void setProductRelativeTypeText(String productRelativeTypeText) 
    {
        this.productRelativeTypeText = productRelativeTypeText;
    }

    public String getProductRelativeTypeText() 
    {
        return productRelativeTypeText;
    }
    public void setTrxNo(String trxNo) 
    {
        this.trxNo = trxNo;
    }

    public String getTrxNo() 
    {
        return trxNo;
    }
    public void setTrxType(String trxType) 
    {
        this.trxType = trxType;
    }

    public String getTrxType() 
    {
        return trxType;
    }
    public void setTrxNonceStr(String trxNonceStr) 
    {
        this.trxNonceStr = trxNonceStr;
    }

    public String getTrxNonceStr() 
    {
        return trxNonceStr;
    }
    public void setPayerUserId(Long payerUserId) 
    {
        this.payerUserId = payerUserId;
    }

    public Long getPayerUserId() 
    {
        return payerUserId;
    }
    public void setPayerName(String payerName) 
    {
        this.payerName = payerName;
    }

    public String getPayerName() 
    {
        return payerName;
    }
    public void setPayerFee(BigDecimal payerFee) 
    {
        this.payerFee = payerFee;
    }

    public BigDecimal getPayerFee() 
    {
        return payerFee;
    }
    public void setOrderIp(String orderIp) 
    {
        this.orderIp = orderIp;
    }

    public String getOrderIp() 
    {
        return orderIp;
    }

    public void setOrderFrom(String orderFrom) 
    {
        this.orderFrom = orderFrom;
    }

    public String getOrderFrom() 
    {
        return orderFrom;
    }
    public void setPayStatus(Integer payStatus) 
    {
        this.payStatus = payStatus;
    }

    public Integer getPayStatus() 
    {
        return payStatus;
    }
    public void setPayType(String payType) 
    {
        this.payType = payType;
    }

    public String getPayType() 
    {
        return payType;
    }
    public void setPayBankType(String payBankType) 
    {
        this.payBankType = payBankType;
    }

    public String getPayBankType() 
    {
        return payBankType;
    }
    public void setPayAmount(BigDecimal payAmount) 
    {
        this.payAmount = payAmount;
    }

    public BigDecimal getPayAmount() 
    {
        return payAmount;
    }
    public void setPaySuccessAmount(BigDecimal paySuccessAmount) 
    {
        this.paySuccessAmount = paySuccessAmount;
    }

    public BigDecimal getPaySuccessAmount() 
    {
        return paySuccessAmount;
    }
    public void setPaySuccessTime(Date paySuccessTime) 
    {
        this.paySuccessTime = paySuccessTime;
    }

    public Date getPaySuccessTime() 
    {
        return paySuccessTime;
    }
    public void setPaySuccessProof(String paySuccessProof) 
    {
        this.paySuccessProof = paySuccessProof;
    }

    public String getPaySuccessProof() 
    {
        return paySuccessProof;
    }
    public void setPaySuccessRemarks(String paySuccessRemarks) 
    {
        this.paySuccessRemarks = paySuccessRemarks;
    }

    public String getPaySuccessRemarks() 
    {
        return paySuccessRemarks;
    }
    public void setPayCompleteTime(Date payCompleteTime) 
    {
        this.payCompleteTime = payCompleteTime;
    }

    public Date getPayCompleteTime() 
    {
        return payCompleteTime;
    }
    public void setRefundNo(String refundNo) 
    {
        this.refundNo = refundNo;
    }

    public String getRefundNo() 
    {
        return refundNo;
    }
    public void setRefundAmount(Long refundAmount) 
    {
        this.refundAmount = refundAmount;
    }

    public Long getRefundAmount() 
    {
        return refundAmount;
    }
    public void setRefundDesc(String refundDesc) 
    {
        this.refundDesc = refundDesc;
    }

    public String getRefundDesc() 
    {
        return refundDesc;
    }
    public void setRefundTime(Date refundTime) 
    {
        this.refundTime = refundTime;
    }

    public Date getRefundTime() 
    {
        return refundTime;
    }
    public void setThirdpartyType(String thirdpartyType) 
    {
        this.thirdpartyType = thirdpartyType;
    }

    public String getThirdpartyType() 
    {
        return thirdpartyType;
    }
    public void setThirdpartyAppid(String thirdpartyAppid) 
    {
        this.thirdpartyAppid = thirdpartyAppid;
    }

    public String getThirdpartyAppid() 
    {
        return thirdpartyAppid;
    }
    public void setThirdpartyMchId(String thirdpartyMchId) 
    {
        this.thirdpartyMchId = thirdpartyMchId;
    }

    public String getThirdpartyMchId() 
    {
        return thirdpartyMchId;
    }
    public void setThirdpartyTradeType(String thirdpartyTradeType) 
    {
        this.thirdpartyTradeType = thirdpartyTradeType;
    }

    public String getThirdpartyTradeType() 
    {
        return thirdpartyTradeType;
    }
    public void setThirdpartyTransactionId(String thirdpartyTransactionId) 
    {
        this.thirdpartyTransactionId = thirdpartyTransactionId;
    }

    public String getThirdpartyTransactionId() 
    {
        return thirdpartyTransactionId;
    }
    public void setThirdpartyUserOpenid(String thirdpartyUserOpenid) 
    {
        this.thirdpartyUserOpenid = thirdpartyUserOpenid;
    }

    public String getThirdpartyUserOpenid() 
    {
        return thirdpartyUserOpenid;
    }

    public String getThirdpartyPrepayid() {
        return thirdpartyPrepayid;
    }

    public void setThirdpartyPrepayid(String thirdpartyPrepayid) {
        this.thirdpartyPrepayid = thirdpartyPrepayid;
    }

    public void setStatus(Integer status)
    {
        this.status = status;
    }

    public Integer getStatus() 
    {
        return status;
    }

    /**
     * 是否可以对支付记录进行手动入账
     *
     * @return
     */
    public boolean isCanUpdateByUser() {
        Integer payStatus = getPayStatus();
        String payType = getPayType();

        return payStatus != null
                && payStatus == PayStatus.UNPAY.getStatus()
                && (PaymentRecordConstants.PAY_TYPE_WECHATX.equals(payType) || PaymentRecordConstants.PAY_TYPE_ALIPAYX.equals(payType));
    }

    /**
     * 是否支付成功
     *
     * @return
     */
    public boolean isPaySuccess() {
        return getPayStatus() != null && getPayStatus() >= PayStatus.SUCCESS_ALIPAY.getStatus();
    }


    /**
     * 是否处于预支付状态
     *
     * @return
     */
    public boolean isPayPre() {
        return getPayStatus() != null && PayStatus.UNPAY.getStatus() == getPayStatus();
    }

    public String getPayStatusStr() {
        return PayStatus.getTextByInt(getPayStatus());
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
            .append("id", getId())
            .append("productTitle", getProductTitle())
            .append("productSummary", getProductSummary())
            .append("productRelativeId", getProductRelativeId())
            .append("productRelativeType", getProductRelativeType())
            .append("productRelativeTypeText", getProductRelativeTypeText())
            .append("trxNo", getTrxNo())
            .append("trxType", getTrxType())
            .append("trxNonceStr", getTrxNonceStr())
            .append("payerUserId", getPayerUserId())
            .append("payerName", getPayerName())
            .append("payerFee", getPayerFee())
            .append("orderIp", getOrderIp())
            .append("orderFrom", getOrderFrom())
            .append("payStatus", getPayStatus())
            .append("payType", getPayType())
            .append("payBankType", getPayBankType())
            .append("payAmount", getPayAmount())
            .append("paySuccessAmount", getPaySuccessAmount())
            .append("paySuccessTime", getPaySuccessTime())
            .append("paySuccessProof", getPaySuccessProof())
            .append("paySuccessRemarks", getPaySuccessRemarks())
            .append("payCompleteTime", getPayCompleteTime())
            .append("refundNo", getRefundNo())
            .append("refundAmount", getRefundAmount())
            .append("refundDesc", getRefundDesc())
            .append("refundTime", getRefundTime())
            .append("thirdpartyType", getThirdpartyType())
            .append("thirdpartyAppid", getThirdpartyAppid())
            .append("thirdpartyMchId", getThirdpartyMchId())
            .append("thirdpartyTradeType", getThirdpartyTradeType())
            .append("thirdpartyTransactionId", getThirdpartyTransactionId())
            .append("thirdpartyUserOpenid", getThirdpartyUserOpenid())
            .append("thirdpartyPrepayid", getThirdpartyPrepayid())
            .append("remark", getRemark())
            .append("status", getStatus())
            .append("updateTime", getUpdateTime())
            .append("createTime", getCreateTime())
            .toString();
    }
}
